<template>
  <div v-loading.lock="loading" class="base-content">
    <div class="basic-info">
      <!--列表-->
      <el-table
        v-loading="tableLoad"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%"
      >
        <el-table-column align="center" :label="dataList.number" width="50">
          <template slot-scope="scope">
            {{ scope.$index + 1 }}
          </template>
        </el-table-column>
        <el-table-column prop="workFlowDictName" :label="dataList.ApprovalName" />
        <el-table-column
          v-if="systemType == 'cdc'"
          prop="sampleNum"
          :label="dataList.SampleNumber"
        />
        <el-table-column prop="content" :label="dataList.ContentSummary" />
        <el-table-column prop="remark" :label="dataList.Remark">
          <template slot-scope="scope">
            <div v-html="scope.row.remark"></div>
          </template>
        </el-table-column>
        <el-table-column prop="submitName" :label="dataList.Submitter" />
        <el-table-column prop="submitDate" :label="dataList.SubmitTime" />
        <el-table-column prop="newAuditStatusString" :label="dataList.FinalApprovalStatus" />
        <el-table-column :label="btn.operate" width="140">
          <template slot-scope="{ row }">
            <div class="base-table-operation">
              <el-link
                v-if="row.isAllowWithdraw == 1"
                type="danger"
                @click="chehuiDialog(row)"
                >{{ dataList.Retract }}</el-link
              >
              <el-link v-rights="'detail'" type="primary" @click="detail(row)"
                >{{ btn.Look }}</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <WorkFlowGetDetailDialog
      v-if="isShowDialog"
      :is-show-dialog.sync="isShowDialog"
      :edit-id="editId"
      :task-data="taskData"
      :report-data="reportData"
      :row="rowData"
      :done="true"
      :custom-class="customClass"
    />
    <el-dialog
      v-if="isShowChildDialog"
      class="base-dialog"
      :custom-class="' panna-dialog_small'"
      :title="dataList.ReasonForWithdrawal"
      :visible.sync="isShowChildDialog"
      :append-to-body="true"
      :before-close="handleCloseChildDialog"
      @closed="closedChildDialog"
    >
      <el-form
        ref="ruleForm"
        :rules="rules"
        label-width="100px"
        class="demo-ruleForm"
        :model="ruleForm"
      >
        <el-form-item :label="dataList.ReasonForWithdrawal" prop="remark">
          <el-input
            v-model="rowData.remark"
            type="textarea"
            maxlength="80"
            show-word-limit
          ></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="base-dialog-footer">
        <el-button type="primary" @click="chehui">{{ btn.Confirm }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { getToken } from "../../utils/auth";
import {
  GetWorkFlowStatusGetListHistory,
  WorkFlowCheHuiFlag,
  WorkFlowCheHui,
} from "../../api/WorkFlow/WorkFlow";
import WorkFlowGetDetailDialog from "./WorkFlowGetDetailDialog.vue";
export default {
  name: "WorkFlowGetDone",
  components: { WorkFlowGetDetailDialog },
  props: {
    id: {
      type: Number,
      default: 0,
    },
    systemType: {
      type: String,
      default: "",
    },
    remark: {
      type: String,
      default: "",
    },
    submitName: {
      type: String,
      default: "",
    },
    workFlowDictcode: {
      type: String,
      default: "",
    },
    sampleNum: {
      type: String,
      default: "",
    },
    pageInfo: {
      type: Object,
      default: () => { },
    },
  },
  data() {
    return {
      isShowChildDialog: false,
      reportData: {},
      taskData: {
        id: 0,
        entrustTaskNum: "",
        entrustOrderNumList: "",
        detectionItemName: "",
        sampleInfoName: "",
        sampleInfoNum: "",
        planDetectionDate: "",
        remark: "",
      },
      customClass: "panna-dialog_medium",
      rowData: {},
      pageType: "",
      showEdit: [40, 60],
      filterForm: {
        auditStatus: 10,
      },
      token: { Authorization: getToken() },
      visible: false,
      editId: "",
      EditIsShowDialog: false,
      isShowDialog: false,
      isShowUpdateDialog: false,
      tableLoad: false,
      loading: false,
      searchLoading: false,
      tableData: [],
      total: 0,
      pageCount: 0,
    };
  },
  computed: {
    btn() {
      return this.$t("ModuleWorkFlow.buttons");
    },
    dataList() {
      return this.$t("ModuleWorkFlow.WorkFlow");
    },
  },
  created() {
    // this.filterForm.id = this.id;
    // this.filterForm.workFlowDictcode = this.workFlowDictcode;
    // this.filterForm.remark = this.remark;
    // this.filterForm.submitName = this.submitName;
    this.getList();
  },
  methods: {
    chehui() {
      WorkFlowCheHui(this.rowData)
        .then((res) => {
          if (res.data) {
            this.$message.success(this.$t("ModuleWorkFlow.buttons.Success"));
            this.isShowChildDialog = false;
            return;
          }
        })
        .catch((res) => { });
    },
    chehuiDialog(row) {
      this.rowData = row;
      this.rowData.dataGuid = this.rowData.dataGroup;
      WorkFlowCheHuiFlag(this.rowData).then((res) => {
        if (!res.data) {
          this.$message.warning(this.$t("ModuleWorkFlow.WorkFlow.NotAudited"));
          return;
        } else {
          // 判定没有下一个节点，或者下个节点没审批
          this.isShowChildDialog = true;
        }
      });
    },
    handleCloseChildDialog() {
      this.$refs["ruleForm"].resetFields();
      this.isShowChildDialog = false;
    },
    closedChildDialog() {
      this.$refs["ruleForm"].resetFields();
      this.isShowChildDialog = false;
    },
    detail(row) {
      this.rowData = row;
      this.rowData.isShowHistory = true;

      this.customClass = row.className;
      this.editId = row.auditDataId;
      this.isShowDialog = true;
    },

    cancelForm() {
      this.$refs.filterForm.resetFields();
      this.getList("filter");
    },

    importError() {
      this.loading = false;
      this.$message.error(this.$t("ModuleWorkFlow.buttons.ImportFailure"));
    },
    uploading() {
      this.loading = true;
    },
    editUnit(row) {
      this.editId = row.id;
      this.isShowUpdateDialog = true;
    },

    close() {
      this.editId = "";
      this.getList();
    },
    getList(flag) {
      this.filterForm.id = this.id;
      this.filterForm.workFlowDictcode = this.workFlowDictcode;
      this.filterForm.remark = this.remark;
      this.filterForm.submitName = this.submitName;
      this.searchLoading = true;
      this.tableLoad = true;
      if (flag) {
        this.pageInfo.pageIndex = 1;
      }
      GetWorkFlowStatusGetListHistory({
        ...this.filterForm,
        ...this.pageInfo,
      })
        .then((res) => {
          // 分页序号连续
          this.tableData = res.data.dataList;
          this.$emit("on-change-page-info", res.data.total);
          this.tableLoad = false;
          this.searchLoading = false;
        })
        .catch(() => {
          this.tableData = [];
          this.tableLoad = false;
          this.searchLoading = false;
        });
    },
    // 切换页码
    changePage(page) {
      this.getList();
    },
    sizeChange(val) {
      this.getList();
    },
    // 新增客户信息
    addUnit() {
      this.isShowDialog = true;
    },
  },
};
</script>
